//
//  LWNewFeatureViewCell.swift
//  ios8-01 weibo框架搭建
//
//  Created by blue on 16/2/29.
//  Copyright © 2016年 honeywell. All rights reserved.
//

import UIKit

class LWNewFeatureViewCell: UICollectionViewCell {
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        
        
    }
    
    
    
    override func layoutSubviews() {
        
        //设置背景图片和按钮的frame
        
        self.prepareUI()
        
    }
    
    func  prepareUI(){
        
        
        //添加子控件
        self.addSubview(backImageView)
        self.addSubview(startBtn)
        //设置约束
        self.setupFrame()
    }
    
    func  setupFrame(){
        
        backImageView.translatesAutoresizingMaskIntoConstraints = false
        
        let  top = NSLayoutConstraint(item: backImageView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 0)
        self.addConstraint(top)
        
        let  bottom = NSLayoutConstraint(item: backImageView, attribute: NSLayoutAttribute.Bottom, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0)
        self.addConstraint(bottom)
        
        let  left = NSLayoutConstraint(item: backImageView, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 0)
        self.addConstraint(left)
        
        let  right = NSLayoutConstraint(item: backImageView, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self, attribute: NSLayoutAttribute.Trailing, multiplier: 1, constant: 0)
        self.addConstraint(right)



        
    }

    
    //cell的背景图片
    lazy  var    backImageView : UIImageView = {
        
        let   imageView = UIImageView()
        
        imageView.image = UIImage(named: "new_feature_1")
        imageView.sizeToFit()
        
        return  imageView
    }()
    
   //开始按钮
    lazy  var    startBtn : UIButton = {
        
       let  btn = UIButton(type: UIButtonType.Custom)
        
       // btn.setBackgroundImage(UIImage(named: ""), forState: UIControlState.Normal
        btn.titleLabel?.text = "开始浏览"
        
        
        return  btn
        
    }()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
